package com.knight.concurrent.chapter6;

/**
 * 线程中断
 *
 * @author: knight
 * @Date: 2019-02-28 22:22
 */
public class ThreadInterrupt {

    public static void main(String[] args) throws InterruptedException {

        Thread t = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    System.out.println("捕获到中断异常"+Thread.interrupted());
                    e.printStackTrace();
                }
            }
        });

        t.start();

        Thread.sleep(200);
        System.out.println(t.isInterrupted());
        t.interrupt();
        Thread.sleep(200);
        System.out.println(t.isInterrupted());


    }

}
